# -*- coding: utf-8 -*-

import pymysql
import sys
import os
sys.path.append('../')
from configs import config


# 替换字典
replace_dict = {
    r'\n': '',
    r'\t': '',
}


def pymysqlAction(sql):
    '''
    pymysql操作
    :return:
    '''
    conf = config.get_config()
    # 建立一个连接
    conn = pymysql.connect(host=conf['mysql_config']['mysql_conf']['mysql_host'], port=conf['mysql_config']['mysql_conf']['mysql_port'], user=conf['mysql_config']['mysql_conf']['mysql_user'], password=conf['mysql_config']['mysql_conf']['mysql_password'], db=conf['mysql_config']['mysql_conf']['mysql_db'], charset=conf['mysql_config']['mysql_conf']['mysql_charset'])
    # 创建一个游标
    cursor = conn.cursor()
    # 执行 SQL 语句
    cursor.execute(sql)
    # 提交
    conn.commit()
    # 关闭游标
    cursor.close()
    # 关闭数据库连接
    conn.close()
